home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 03 Pathfinding with Astar / 03 Higgins / Listing2.cpp < prev   
Encoding:
Text File  |  2001-12-09  |  1.6 KB  |  57 lines

  1. /* Copyright (C) Dan Higgins, 2001. 
  2.  * All rights reserved worldwide.
  3.  *
  4.  * This software is provided "as is" without express or implied
  5.  * warranties. You may freely copy and compile this source into
  6.  * applications you distribute provided that the copyright text
  7.  * below is included in the resulting source code, for example:
  8.  * "Portions Copyright (C) Dan Higgins, 2001"
  9.  */
  10.  
  11. // An example of the path manager's update follows:
  12.  
  13. // Note: Using Revs as short for Revolutions
  14. // to conserve code space here
  15. // While we have paths to process and haven't
  16. // exceeded our pathfinding revolutions-per-tick cap...
  17. while(this->mPathsQueue.size() &&
  18.     theRevsCompleted < kMaxRevsPerGameTick)
  19. {
  20.     // Get the first pathfinder
  21.     // impl note: mPathsQueue is an STL deque
  22.     thePath = this->mPathsQueue.front();
  23.  
  24.     // Run, Run, Run!
  25.     thePath->RunAStar();
  26.  
  27.     // How many revolutions so far?
  28.     theRevsCompleted += thePath->GetRevsThisRun();
  29.  
  30.     // If we aren't still working, then we are done!
  31.     if (!thePath->GetIsStillWorking())
  32.     {
  33.         // Post processing
  34.         this->ProcessFinishedPath(thePath);
  35.     }
  36.     else
  37.     {
  38.         // Is it less than the max revolutions allowed?
  39.         if(thePath->GetRevsPerRun() < kMaxRevsPerRun)
  40.         {
  41.             // Set its revolution cap X more
  42.             // each time so the more often it moves
  43.             // through the queue, the more it
  44.             // processes each time.
  45.             theRevsPerRun = thePath->GetRevsPerRun();
  46.             thePath->SetRevsPerRun(theRevsPerRun + 1);
  47.         }
  48.  
  49.         // Take it off the front of the queue
  50.         // and put it on the rear of the queue.
  51.         this->mPathsQueue.push_back(thePath);
  52.     }
  53.  
  54.     // Remove it from the front.
  55.     this->mPathsQueue.pop_front();
  56. }
  57.